package se.cbb.scripts;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;

import se.cbb.misc.SequenceFileWriter;

public class RemovingSingleGeneClusters {

	public static void main(String[] args) {
		try {
			String path = "/Users/rhali/Documents/Projects/GrandOrthology/Mapping/";
			File folder = new File(path);
			File[] listOfFiles = folder.listFiles();
			

			for(int i = 1; i < listOfFiles.length; i++) {
				String fileName = listOfFiles[i].getName();

				BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
	
				int index = 0;

				String str;
				HashSet<String> set = new HashSet<String>();
				while ((str = bufferedreader.readLine()) != null) {
					set.add(str.split("\t")[1]);
					index++;
				}
				
				Object[] temp = set.toArray();
				SequenceFileWriter.writeAndAppendString(path, "Size.txt", fileName + "\t" + String.valueOf(index) + "\t" + set.size() + "\t" + temp[0]);
				for(int j = 1; j < temp.length; j++)
					SequenceFileWriter.writeAndAppendString(path, "Size.txt", "\t" + temp[j]);
				SequenceFileWriter.writeAndAppendLine(path, "Size.txt", "");
				bufferedreader.close();
			}
		} catch (Exception e) {
			System.out.println("Error : " + e.getMessage());
		}
		

	}

}
